﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using WHC.OrderWater.Commons;
using System.Diagnostics;
using WHC.Security.Common;

namespace WHC.Security.UI
{
    public class Portal
    {
        public static GlobalControl gc = new GlobalControl();
        public static void StartLogin()
        {
            Logon dlg = new Logon();
            dlg.StartPosition = FormStartPosition.CenterScreen;
            if (DialogResult.OK == dlg.ShowDialog())
            {
                if (dlg.bLogin)
                {
                    MainForm MainDialog = new MainForm();
                    gc.MainDialog = MainDialog;

                    MainDialog.ShowDialog();
                }
            }
        }

        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        private static void Main()
        {
            DevExpress.UserSkins.OfficeSkins.Register();
            DevExpress.UserSkins.BonusSkins.Register();
            DevExpress.Skins.SkinManager.EnableFormSkins();

            Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //登陆界面
            Logon dlg = new Logon();
            dlg.StartPosition = FormStartPosition.CenterScreen;
            if (DialogResult.OK == dlg.ShowDialog())
            {
                if (dlg.bLogin)
                {
                    gc.MainDialog = new MainForm();
                    gc.MainDialog.StartPosition = FormStartPosition.CenterScreen;
                    //gc.MainDialog.ShowInTaskbar = true;
                    Application.Run(gc.MainDialog);
                }
            }
            dlg.Dispose();
        }

        private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs ex)
        {
            LogHelper.Error(ex.Exception);
            string message = string.Format("{0}\r\n操作发生错误，您需要退出系统么？", ex.Exception.Message);
            if (DialogResult.Yes == MessageDxUtil.ShowYesNoAndError(message))
            {
                Application.Exit();
            }
        }
    }
}
